package com.sdy.hospitalguard.embed.keepalive.manager.netty.netty.codec;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import java.util.List;

@Slf4j
public class HttpEncoder<I> extends MessageToMessageEncoder {

    /**
     * request编码器
     */
    private UnvHttpRequestEncoder httpRequestEncoder = new UnvHttpRequestEncoder();

    /**
     * response编码器
     */
    private UnvHttpResponseEncoder httpResponseEncoder = new UnvHttpResponseEncoder();


    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, List out) throws Exception {
        if (msg instanceof HttpRequest) {
            httpRequestEncoder.encode(ctx, msg, out);
        } else if (msg instanceof HttpResponse) {
            httpResponseEncoder.encode(ctx, msg, out);
        }
    }

}
